package com.zy.web.controller.bs;

import com.zy.utils.tree.BaseTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zy.entity.bs.CarType;
import com.zy.pojo.query.bs.CarTypeQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.CarTypeService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.Serializable;

@RequestMapping({"bs/carType","m/bs/carType"})
@Controller
public class CarTypeController extends BaseController {

	@Autowired
	private CarTypeService carTypeService;

	/**
	 * 分页
 	 * 
 	 * @param carTypeQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageCarType")
	@ResponseBody
	public PageVo pageCarType(CarTypeQuery carTypeQuery, Integer start, Integer limit) {
		return this.carTypeService.pageCarType(carTypeQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param carType
	 * @return
	 */
	@RequestMapping(value = "saveCarType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveCarType(CarType carType) {
		try {
			carType.setCreateUserId(this.getCurrentUser().getId());
			carType.setModifyUserId(this.getCurrentUser().getId());
			this.carTypeService.saveCarType(carType);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param carType
	 * @return
	 */
	@RequestMapping(value = "updateCarType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateCarType(CarType carType) {
		try {
			carType.setModifyUserId(this.getCurrentUser().getId());
			this.carTypeService.updateCarType(carType);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeCarType", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeCarType(long id) {
		try {
			this.carTypeService.removeCarType(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.carTypeService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

    @RequestMapping(value = "front/carTree")
    @ResponseBody
    public ResultVo carTree() {
        try {

            return ResultUtil.success((Serializable) carTypeService.carType());
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }
    }

}